package com.mz.ozy.widget.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mz.ozy.R;
import com.mz.ozy.activity.me.MeRechargeActivity;
import com.mz.ozy.adapter.PayActivityAdapter;
import com.mz.ozy.adapter.PayCardAdapter;
import com.mz.ozy.bean.ExchangeOrderBean;
import com.mz.ozy.bean.VoucherBean;

import java.util.List;

/**
 * Created by administrator on 2019/3/28.
 * 支付选择弹窗
 */
public class PayCardDialog extends BaseDialog implements View.OnClickListener {

    private RecyclerView recyclerView;
    private PayCardAdapter mAdapter;
    private ExchangeOrderBean.CardMapBean cardMapBean;

    public PayCardDialog(Activity mContext) {
        super(mContext, R.layout.dialog_pay_card, Gravity.BOTTOM, true, true, R.style.dialog_pay_theme);
        initView();
    }

    private void initView() {
        recyclerView = getView(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        getView(R.id.tv_confirm).setOnClickListener(this);
    }

    public void setData(List<ExchangeOrderBean.CardMapBean> acListBeans, int id) {
        mAdapter = new PayCardAdapter(acListBeans, id);
        recyclerView.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                cardMapBean = mAdapter.getItem(position);
                mAdapter.setSelectPosition(position);
                mAdapter.notifyDataSetChanged();
            }
        });
    }

    private onDialogListener mListener;

    public void setOnDialogListener(onDialogListener listener) {
        mListener = listener;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_confirm:
                if (mListener != null && cardMapBean != null) {
                    mListener.onConfirm(cardMapBean);
                }
                toggleDialog();
                break;
        }
    }

    public interface onDialogListener {
        void onConfirm(ExchangeOrderBean.CardMapBean item);
    }
}
